console.log("ff test")

const path = require('path');
const timeUtil = require('../util/TimeUtils')

let filePath = "D:/hls_genrate/my_genrator/small_other.mp4";
let out = "D:/hls_genrate/my_genrator/out/temp/";
let water_mark = {
    x: 100,
    y: 80,
    s: 80
}
let water_scale = parseInt(255 / 100 * water_mark.s) + ":" + parseInt(80 / 100 * water_mark.s);
// let extra = "-b:v 192k -b:a 128k -s 426x240 -r 24";
let extra = "-b:v 192k -b:a 128k -r 24";

let cmd = 'ffmpeg -y -i ' + filePath + ' -vf "movie=../../static/Watermark.png, scale=' + water_scale + ' [watermark]; [in][watermark] overlay=' + water_mark.x + ':' + water_mark.y + '[out]" -sc_threshold 0 -movflags frag_keyframe+empty_moov+default_base_moof -hls_time 8 -hls_playlist_type vod -hls_segment_type fmp4 ' + extra + " -c:v hevc -tag:v hvc1 -preset:v ultrafast -hls_segment_filename " + out + "/%4d.m4s " + out + "/index.m3u8";
// let cmd = "ping nur.cn";

let duration = 60.024000;

console.log(cmd)

var nrc = require('node-run-cmd');
var dataCallback = function (data) {
    var reg = /time=(.+) bitrate/;
    let result = reg.exec(data);
    if (result && result.length > 1) {
        let curTime = result[1];

        let per = timeUtil.getTime2Percent(duration, curTime);
        console.log(per + "%")
    } else {
        // console.log(data)
    }
};

nrc.run(cmd, {onData: dataCallback, onError: dataCallback});
